<template>
  <div class="box">
    <div>
      <eagle-tab-page-list
        ref="pageTabList"
        url="/WhInvestigationReport/GetPageData"
        :params="params"
        placeholder="请输入事故名称,事故编号搜索"
        @initActive="_initActive"
        @initList="_initList"
      >
        <div v-if="this.active === 0">
          <eagle-cell
            style="margin-top: 10px"
            class="card"
            v-for="(item, index) in list"
            :key="index"
          >
            <div>
              <div @click="view(item)">
                <eagle-row
                  gutter="15"
                  style="word-break:break-all"
                >
                  <eagle-col>
                    <b style="font-size: 13px">{{ item.AccidentName }}</b>
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="15">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />事故编号：{{ item.IncidentNumber }}
                  </eagle-col>
                </eagle-row>
                <!-- <van-row gutter="20">
                                <van-col style="word-break:break-all" >
                                    <img class="icon" src="@/assets/Images/AppIcon/icon_list_type.png" />事故名称:{{ item.AccidentName }}
                                </van-col>
                            </van-row> -->

                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_date.png"
                    />事故发生日期：{{ item.AccidentDate | formatDateTime }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />事故分类：{{ item.AttidentClassification }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />事故分级：{{ item.AttidentgRading }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />潜在风险：{{ item.PotentialRisk }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_user.png"
                    />创建人：{{ item.CreateChnName }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_date.png"
                    />创建日期：{{ item.CreateDate | formatDateTime }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />区域部门：{{ item.AccidentDepartmentName }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />状态：{{ getStatus(item.Status) }}
                  </eagle-col>
                </eagle-row>
                <van-divider />
              </div>
              <div class="op_btn">
                <div
                  class="btn_item"
                  v-if="(rightValue & 8) > 0&& item.Status==0"
                  @click="edit1(item)"
                >
                  <img
                    src="@/assets/Images/AppIcon/icon_list_edit.png"
                    alt=""
                  />
                  <div class="mr-10">编辑</div>
                </div>
              </div>
            </div>
          </eagle-cell>
        </div>
        <div v-if="this.active === 1">
          <eagle-cell
            style="margin-top: 10px"
            class="card"
            v-for="(item, index) in list"
            :key="index"
          >
            <div>
              <div @click="view2(item)">
                <b style="font-size: 13px">{{ item.AccidentName }}</b>
                <eagle-row gutter="15">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />事故编号：{{ item.IncidentNumber }}
                  </eagle-col>
                </eagle-row>
                <!-- <van-row gutter="20">
                                <van-col style="word-break:break-all" >
                                    <img class="icon" src="@/assets/Images/AppIcon/icon_list_type.png" />事故名称:{{ item.AccidentName }}
                                </van-col>
                            </van-row> -->

                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_date.png"
                    />事故发生日期：{{ item.AccidentDate | formatDateTime }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />事故分类：{{ item.AttidentClassification }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />事故分级：{{ item.AttidentgRading }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />潜在风险：{{ item.PotentialRisk }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_date.png"
                    />创建日期：{{ item.CreateDate | formatDateTime }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_user.png"
                    />调查组长：{{ item.UserChnName1 }}
                  </eagle-col>
                </eagle-row>

                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />区域部门：{{ item.AccidentDepartmentName }}
                  </eagle-col>
                </eagle-row>
                <eagle-row gutter="20">
                  <eagle-col>
                    <img
                      class="icon"
                      src="@/assets/Images/AppIcon/icon_list_type.png"
                    />状态：{{ getStatus(item.Status) }}
                  </eagle-col>
                </eagle-row>
                <van-divider />
              </div>
              <div class="op_btn">
                <div
                  class="btn_item"
                  v-if="(rightValue & 8) > 0&&(item.Status ==10|| item.Status==0)"
                  @click="deletePlan(item)"
                >
                  <img
                    src="@/assets/Images/AppIcon/icon_list_delete.png"
                    alt=""
                  />
                  <div class="mr-10">删除</div>
                </div>
                <div
                  class="btn_item"
                  v-if="(rightValue & 8) > 0&& item.Status==0"
                  @click="edit2(item)"
                >
                  <img
                    src="@/assets/Images/AppIcon/icon_list_edit.png"
                    alt=""
                  />
                  <div class="mr-10">编辑</div>
                </div>
              </div>
              <!-- <div class="op_btn">
                                <div class="btn_item" @click="Share(item)">
                                    <img src="@/assets/Images/AppIcon/icon_list_edit.png" alt="" />
                                    <div class="mr-10">分享学习</div>
                                </div>
                            </div> -->
            </div>
          </eagle-cell>
        </div>
      </eagle-tab-page-list>
    </div>
  </div>
</template>
<script>
import DialogPageList from "@/components/DialogPageList.vue";
import { getMenuByMenuCode } from "@/api/common";
import PageTabList from "@/components/PageTabList/PageTabList.vue";
export default {
  components: {
    PageTabList,
    DialogPageList,
  },
  data() {
    return {
      value: "",
      list: [],
      isEdit: false,
      rightValue: 0,
      AccidentNumber: "",
      tabName: "tab1",
      active: 0,
      params: [
        {
          title: "初始报告",
          dataType: "InitialReport",
        },
        {
          title: "调查报告",
          dataType: "AllList",
        },
      ],
      listUser: [],
    };
  },
  created() {
    this.getMenuByMenuCode();
  },
  methods: {
    _initActive(active) {
      this.active = active;
    },
    _initList(list) {
      this.list = list;
    },
    getMenuByMenuCode() {
      var me = this;
      getMenuByMenuCode("WH_AccidentInitial_Report_Allocation").then((res) => {
        me.rightValue = res.data ? res.data.RoleRightValue : 0;
      });
    },
    _initListUser(list) {
      this.listUser = list;
    },
    getStatus(val) {
      if (val == 0) {
        return "未提交";
      } else if (val == 5) {
        return "审批中";
      } else {
        return "已审批";
      }
    },
    // share(item) {
    //     const that = this;
    //     that.$dialog
    //         .confirm({
    //             title: "询问",
    //             message: "您确定要分享学习该调查报告吗",
    //         })
    //         .then(() => {
    //             ShareToLearn({ id: item.ID }).then((res) => {
    //                 that.$toast.success("分享成功！");
    //                 this.eee(res.data);
    //             });
    //         })
    //         .catch(() => {
    //             // on cancel
    //         });
    // },
    deletePlan(item) {
      //初始报告删除
      const that = this;

      that.$dialog
        .confirm({
          title: "询问",
          message: "您确定要删除该事故报告吗？",
        })
        .then(() => {
          that.$axios
            .get("/WhInvestigationReport/Delete", { params: { id: item.ID } })
            .then((res) => {
              that.$toast.success("删除成功！");
              setTimeout(() => {
                that.$refs.pageTabList.getList();
              }, 300);
              //that.getMyList();
            });
        })
        .catch(() => {
          // on cancel
        });
    },
    edit1(item) {
      //初始报告编辑
      if (item.ID > 0) {
        this.isEdit = true;
      } else {
        this.isEdit = false;
      }
      this.$router.push({
        path: "/whAccidentInitialReportDetail",
        query: { id: item.ID, allList: true },
      });
    },

    edit2(item) {
      //调查报告编辑;
      if (item.ID > 0) {
        this.isEdit = true;
      } else {
        this.isEdit = false;
      }
      this.$router.push({
        path: "/whInvestigationReportDetail",
        query: { id: item.ID, allList: true },
      });
    },
    view(item) {
      this.$router.push({
        path: "/whAccidentInitialReportView",
        query: { id: item.ID },
      });
    },
    view2(item) {
      this.$router.push({
        path: "/whInvestigationReportView",
        query: { id: item.ID },
      });
    },
  },
};
</script>
<style lang="less" scoped>
.phone {
  position: relative;
  .code {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 12px;
  }
}
.register-info {
  background-color: #e8f1f8;
  padding-bottom: 20px;
}
.img-box {
  height: 50px;
  width: 50px;
  padding: 10px;
  position: absolute;
  left: 50%;
  top: 60px;
  background-color: #fff;
  border-radius: 50%;
  overflow: hidden;
}
.popup-title {
  line-height: 35px;
  padding: 10px;
  font-size: 15px;
  padding-left: 20px;
}

.op_btn {
  display: flex;
  justify-content: flex-end;
  .btn_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>